﻿@using hc.epm.UI.Common;
@using hc.epm.DataModel.Basic;
@using hc.Plat.Common.Extend;
@using hc.epm.Common;
@model IEnumerable<Base_Dep>
@{
    ViewBag.Title = "部门管理";
}
<div class="content-right date-wrap fl c">
    <div class="top-url">
        <span><a href="/home/welcome" target="mainFrame">首页</a>  </span> > <span>部门管理</span> > <span id="companyname-nav"></span>
    </div>
    <div class="container-fluid search mt5 " style="height:700px;padding:0px">

        <div class="table-wrap no-padding" style="padding:0px">
            <form class="layui-form company-wrap" action="" method="get">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="hidden" name="CompanyId" id="CompanyId" value="@ViewBag.CompanyId" />
                        <label class="layui-form-label">部门名称 : </label>
                        <div class="layui-input-inline"><input type="text" name="name" id="name" placeholder="请输入部门名称" autocomplete="off" class="layui-input" value="@ViewBag.Name" /></div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">启用/禁用 : </label>
                        <div class="layui-input-inline">
                            @Html.DropDownList("IsEnable")
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">是否确认 : </label>
                        <div class="layui-input-inline">
                            @Html.DropDownList("IsConfirm")
                        </div>
                    </div>
                    <input type="submit" class="layui-btn layui-btn-radius layui-btn-warm" lay-filter="search" value="搜 索" />
                </div>
            </form>
            <hr style="width:98%;margin: 20px auto">
            <div class="btns padding20">
                <a href="javascript:;" target="mainFrame" data-module="Dep" data-right="add" id="add" class="checkright">新增部门</a>
                <a href="javascript:;" data-module="Dep" data-right="delete" id="delete" class="checkright">删 除</a>
            </div>
            <div class="layui-form padding20">
                <table class="layui-table">
                    <thead>
                        <tr>
                            <th width="50" class="table-center">
                                <input type="checkbox" lay-skin="primary" lay-filter="allChoose" />
                                <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
                            </th>
                            <th width="80" class="table-center">序号</th>
                            <th class="table-left">编码</th>
                            <th width="25%" class="table-left">部门名称</th>
                            <th width="25%" class="table-left">上级部门</th>
                            <th width="7%" class="table-center">启用/禁用</th>
                            <th width="7%" class="table-center">确认状态</th>
                            <th width="6%" class="table-center">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @{
                            int index = 0;
                        }
                        @if (Model != null && Model.Count() > 0)
                        {
                            foreach (var item in Model)
                            {
                                index++;
                                <tr>
                                    <td class="table-center">
                                        <input type="checkbox" lay-skin="primary" />
                                        <input type="hidden" name="id-@item.Id" id="id-@item.Id" value="@item.Id" />
                                    </td>
                                    <td class="table-center">@index</td>
                                    <td class="table-left">@item.Code</td>
                                    <td class="table-left">@item.Name</td>
                                    <td class="table-left">@item.PreName</td>
                                    <td class="table-center">
                                        <div class="switch switch-mini" data-on-label="SI" data-off-label="SII">
                                            <input type="checkbox" checked />
                                        </div>
                                        @if (item.IsEnable)
                                        {
                                            <a href="javascript:;" class='change-state check-right' data-itemid="@item.Id" data-value="@item.IsEnable" data-type="1" title="启用/禁用" data-module="Dep" data-right="enable"><i class='glyphicon glyphicon-check handle-blue'></i></a>
                                        }
                                        else
                                        {
                                            <a href="javascript:;" class='change-state check-right' data-itemid="@item.Id" data-value="@item.IsEnable" data-type="1" title="启用/禁用" data-module="Dep" data-right="enable"><i class='glyphicon glyphicon-lock handle-red'></i></a>
                                        }
                                    </td>
                                    <td class="table-center">
                                        @if (item.IsConfirm)
                                        {
                                            <a href="javascript:;" class='change-state check-right' data-itemid="@item.Id" data-value="@item.IsConfirm" data-type="2" title="确认状态" data-module="Dep" data-right="confirm"><i class='glyphicon glyphicon-ok-sign handle-blue'></i></a>
                                        }
                                        else
                                        {
                                            <a href="javascript:;" class='change-state check-right' data-itemid="@item.Id" data-value="@item.IsConfirm" data-type="2" title="确认状态" data-module="Dep" data-right="confirm"><i class='glyphicon glyphicon-question-sign handle-red'></i></a>
                                        }

                                    </td>
                                    <td class="table-center">
                                        <a href="javascript:;" class="editor-link check-right" data-itemid="@item.Id" title="编辑" data-module="Dep" data-right="modify"><i class='glyphicon glyphicon-pencil handle-blue'></i></a>
                                    </td>
                                </tr>
                            }
                        }
                        else
                        {
                            <tr>
                                <td colspan="12" class="table-center">
                                    暂无数据
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>

    </div>
</div>

<script type="text/javascript">
    layui.use(['layer', 'form', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
        //表格全选
        layui.use('form', function () {
            var $ = layui.jquery, form = layui.form;

            //全选
            form.on('checkbox(allChoose)', function (data) {
                var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
                child.each(function (index, item) {
                    item.checked = data.elem.checked;
                });
                form.render('checkbox');
            });

        });
        //删除
        $("#delete").click(function () {
            var chkItems = $('.layui-table tbody input[type="checkbox"]:checked');
            var ids = "";
            chkItems.each(function (index, item) {
                var hfId = $(this).parent().find("input[type='hidden']");
                ids += hfId.val() + ",";
            });
            if (ids != "") {
                parent.layer.confirm("确认要删除所选择的项？", { icon: 3 }, function () {
                    $.post("/Dep/Delete", { ids: ids }, function (data) {
                        if (data.Flag) {
                            parent.layer.msg("删除成功", { time: 1000, icon: 1 });
                            var search = $("form").serialize();
                            window.location.href = "/Dep/Index?pageIndex=1&" + search;
                        } else {
                            parent.layer.alert(data.Message, { icon: 2 });
                        }
                    }, "json");
                }, function () {
                    return;
                })

            } else {
                parent.layer.alert("请先选择要删除的数据", { icon: 2 });
            }
        });
    });
    //增加
    $("#add").click(function () {
        parent.layer.open({
            type: 2,
            title: GetLayerTitle("部门添加"),
            shadeClose: false, //点击遮罩关闭层
            area: [BigLayerWidth, '440px'],
            content: '/Dep/add?CompanyId=' + getUrlParam("CompanyId")
        });
    });
    //修改
    $(".editor-link").click(function () {
        var id = $(this).data("itemid");
        if (id != "") {
            parent.layer.open({
                type: 2,
                title: GetLayerTitle("部门信息编辑"),
                shadeClose: false, //点击遮罩关闭层
                area: [BigLayerWidth, '440px'],
                content: '/Dep/Edit/' + id
            });
        }
    });
    $.post("/Dep/companyInfo", { id: "@ViewBag.CompanyId" }, function (data) {
        if (data.Flag) {
            $("#companyname-nav").text(data.Data.Name);
        } else {
            parent.layer.alert(data.Message, { icon: 3 });
        }
    })
    //启用禁用切换
    $(".change-state").click(function () {
        var id = $(this).data("itemid");
        var value = $(this).data("value");
        var type = $(this).data("type");
        if (id != '') {
            var mes = GetIsEnableLayerMes(value, type);//获取弹出询问层的提示语句
            if (mes == "该条数据已确认不能进行操作？") {//若该条数据为已确认数据将不能改变其确认状态
                parent.layer.alert(mes, { icon: 2 });
            } else {
                parent.layer.confirm(mes, { icon: 3 }, function () {
                    $.post("/Dep/EditState", { id: id, type: type }, function (data) {
                        if (data.Flag == 0) {
                            var search = $("form").serialize();
                            window.location.href = "/Dep/Index?CompanyId=" + getUrlParam("CompanyId") + "&" + search;
                            parent.layer.msg("操作成功！", { time: 1000, icon: 1 });
                        } else {
                            parent.layer.alert(data.Message, { icon: 2 });
                        }
                    })
                })
            }
        } else {
            parent.layer.alert("请选择要操作的项！")
        }
    })
</script>
